<template>
  <image src="@/static/images/01_48db.png" class="banner-img" mode=""></image>
  <view class="home" :style="{'padding-top':navHeight + 'px'}">
    <u-tabs :list="data.list" v-model:current="data.current" key-name="title" activeStyle="color:#fff"
      @change="handleChange" inactiveStyle="color:#fff" lineWidth="19" lineHeight="10rpx" lineColor="#fff"></u-tabs>
    <u-text v-if="data.rankData.title" :text="data.rankData.title.substring(0,2)" margin="55rpx 0 30rpx 30rpx" color="#fff" bold size="25"></u-text>
    <u-text v-if="data.rankData.title" :text="data.rankData.title.substring(2)" margin="0 30rpx" color="#fff" bold size="25"></u-text>
    <view v-for="(item,index) in data.modal" :key="item.id" class="u-p-l-20 u-p-r-20">
      <house-item :item="item" customStyle="background:#fff" :imageWidth="234" imageHeight="192">
        <template #right>
          <view class="u-flex-between u-flex-column u-flex-fill">
            <view class="house-name u-flex-y-center">
              <view class="house-tag" v-if="item.label">{{item.label}}</view>
              <view class="u-line-1 u-flex-1">{{item.title}}</view>
            </view>
            <view class="house-desc" v-if="item.description">“{{item.description}}”</view>
            <view class="house-info">“{{item.space}}㎡ | {{item.house_type_text}}”</view>
            <view class="house-price u-flex-y-center u-flex-between">
              <text>市场价：{{item.market_price}}万</text>
              <text>优惠价：{{item.price}}万</text>
            </view>
          </view>
        </template>
      </house-item>
    </view>
  </view>
</template>

<script setup>
  import {
    computed,
    onMounted,
    ref
  } from 'vue';
  import { ranks } from '../../config/api';
  const navHeight = computed(() => uni.getSystemInfoSync().statusBarHeight + 10)
  const data = ref({
    list: [],
    modal: [],
    current: 0,
    rankData: {}
  })
  onMounted(() => {
    _ranks()
  })
  const handleChange = () => {
    data.value.rankData = data.value.list[data.value.current]
    data.value.modal = data.value.rankData.house_data
  }
  // 房源排行榜
  const _ranks = () => {
    ranks().then(res => {
      data.value.list = res.data
      data.value.modal = res.data[0].house_data
      data.value.rankData = res.data[0]
    })
  }
</script>

<style scoped lang="scss">
  .banner-img {
    width: 100%;
    height: 460rpx;
    position: absolute;
    top: 0;
    left: 0;
  }

  .home {
    position: relative;
    z-index: 1;
  }

  .house-name {
    font-size: 26rpx;
    color: #333;
    font-weight: 800;

    .house-tag {
      width: 112rpx;
      height: 36rpx;
      background: linear-gradient(180deg, #7E7872 0%, #4E4E4E 100%);
      border-radius: 8rpx;
      text-align: center;
      line-height: 36rpx;
      color: #fff;
      font-size: 22rpx;
      font-weight: 500;
      margin-right: 12rpx;

    }
  }

  .house-info {
    font-size: 24rpx;
    font-weight: 500;
    color: #666;
  }

  .house-desc {
    font-size: 22rpx;
    color: #E47117;
  }

  .house-price {
    color: #DF0F0F;
    font-weight: 800;
    font-size: 24rpx;
  }
</style>